<head>
  <meta content="text/html; charset=utf-8" http-equiv="content-type" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>ATP综合测试平台</title>
  <style>
    body {
      background-color: #f2f2f2;
      color: #333;
      margin: 0 auto;
      width: 960px;
    }
    #summary {
      width: 960px;
      margin-bottom: 20px;
    }
    #summary th {
      background-color: skyblue;
      padding: 5px 12px;
    }
    #summary td {
      background-color: lightblue;
      text-align: center;
      padding: 4px 8px;
    }
    .details {
      width: 960px;
      margin-bottom: 20px;
    }
    .details th {
      background-color: skyblue;
      padding: 5px 12px;
    }
    .details tr .passed {
      background-color: lightgreen;
    }
    .details tr .failed {
      background-color: salmon;
    }
    .details tr .unchecked {
      background-color: gray;
    }
    .details td {
      background-color: lightblue;
      padding: 5px 12px;
    }
    .details .detail {
      background-color: lightgrey;
      font-size: smaller;
      padding: 5px 10px;
      text-align: center;
    }
    .details .success {
      background-color: greenyellow;
    }
    .details .error {
      background-color: red;
    }
    .details .failure {
      background-color: salmon;
    }
    .details .skipped {
      background-color: gray;
    }

    .button {
      font-size: 1em;
      padding: 6px;
      width: 4em;
      text-align: center;
      background-color: #06d85f;
      border-radius: 20px/50px;
      cursor: pointer;
      transition: all 0.3s ease-out;
    }
    a.button{
      color: gray;
      text-decoration: none;
    }
    .button:hover {
      background: #2cffbd;
    }

    .overlay {
      position: fixed;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      background: rgba(0, 0, 0, 0.7);
      transition: opacity 500ms;
      visibility: hidden;
      opacity: 0;
    }
    .overlay:target {
      visibility: visible;
      opacity: 1;
    }

    .popup {
      margin: 70px auto;
      padding: 20px;
      background: #fff;
      border-radius: 10px;
      width: 50%;
      position: relative;
      transition: all 3s ease-in-out;
    }

    .popup h2 {
      margin-top: 0;
      color: #333;
      font-family: Tahoma, Arial, sans-serif;
    }
    .popup .close {
      position: absolute;
      top: 20px;
      right: 30px;
      transition: all 200ms;
      font-size: 30px;
      font-weight: bold;
      text-decoration: none;
      color: #333;
    }
    .popup .close:hover {
      color: #06d85f;
    }
    .popup .content {
      max-height: 80%;
      overflow: auto;
      text-align: left;
    }

    @media screen and (max-width: 700px) {
      .box {
        width: 70%;
      }
      .popup {
        width: 70%;
      }
    }

  </style>
</head>

<body>
  <h1>ATP综合测试平台测试报告</h1>

  <h2>统计</h2>
  <table id="summary">

    <tr>
      <th>开始时间</th>
      <td colspan="2">{{time.start_datetime}}</td>
       <th>持续时间</th>
      <td colspan="2">{{ '%0.3f'| format(time.duration|float) }} seconds</td>
    </tr>
{#    <tr>#}
{#      <th>持续时间</th>#}
{#      <td colspan="2">{{ '%0.3f'| format(time.duration|float) }} seconds</td>#}
{#    </tr>#}
    <tr>
      <th>平台信息</th>
      <td>HttpRunner {{ platform.httprunner_version }} </td>
      <td>{{ platform.python_version }} </td>
      <td colspan="2">{{ platform.platform }}</td>
    </tr>
    <tr>
      <th>用例总数</th>
      <th>成功</th>
      <th>失败</th>
      <th>报错</th>
      <th>跳过</th>
      <!-- <th>ExpectedFailure</th>
      <th>UnexpectedSuccess</th> -->
    </tr>
    <tr>
      <td>{{stat.testsRun}}</td>
      <td>{{stat.successes}}</td>
      <td>{{stat.failures}}</td>
      <td>{{stat.errors}}</td>
      <td>{{stat.skipped}}</td>
      <!-- <td>{{stat.expectedFailures}}</td>
      <td>{{stat.unexpectedSuccesses}}</td> -->
    </tr>
  </table>

  <h2>运行详情</h2>

  {% for test_suite_summary in details %}
  {% set suite_index = loop.index %}
  <h3>{{test_suite_summary.name}}</h3>
  <table id="suite_{{suite_index}}" class="details">
{#    <tr>#}
{#      <th>base_url</th>#}
{#      <td colspan="2">{{test_suite_summary.base_url}}</td>#}
{#      <th colspan="2" class="detail">#}
{#        <a class="button" href="#suite_output_{{suite_index}}">parameters & output</a>#}
{#        <div id="suite_output_{{suite_index}}" class="overlay">#}
{#            <div class="popup">#}
{#                <h2>Parameters and Output</h2>#}
{#                <a class="close" href="#suite_{{suite_index}}">&times;</a>#}
{#                <div class="content">#}
{#                  <div style="overflow: auto">#}
{#                      <table>#}
{#                        <tr>#}
{#                          <th>variables</th>#}
{#                          <th>output</th>#}
{#                        </tr>#}
{#                        <tr>#}
{#                          <td>{{test_suite_summary.in_out.in}}</td>#}
{#                          <td>{{test_suite_summary.in_out.out}}</td>#}
{#                        </tr>#}
{#                      </table>#}
{#                  </div>#}
{#                </div>#}
{#            </div>#}
{#        </div>#}
{#      </td>#}
{#    </tr>#}
{#    <tr>#}
{#      <td>TOTAL: {{test_suite_summary.stat.testsRun}}</td>#}
{#      <td>SUCCESS: {{test_suite_summary.stat.successes}}</td>#}
{#      <td>FAILED: {{test_suite_summary.stat.failures}}</td>#}
{#      <td>ERROR: {{test_suite_summary.stat.errors}}</td>#}
{#      <td>SKIPPED: {{test_suite_summary.stat.skipped}}</td>#}
{#    </tr>#}
    <tr>
      <th>状态</th>
      <th colspan="2">用例名称</th>
      <th>响应时间</th>
      <th>详情</th>
      <th>接口类型</th>

      {% for validator  in  test_suite_summary.records[0].meta_data.validators %}
        {% if validator.error_log %}
                  <th >报错类型</th>
        {% endif %}
      {% endfor %}

{#      {% if test_suite_summary.records[0].meta_data.validators %}#}
{##}
{#      {% endif %}#}


    </tr>

    {% for record in test_suite_summary.records %}
    {% set record_index = "{}_{}".format(suite_index, loop.index) %}
    <tr id="record_{{record_index}}">
      <th class="{{record.status}}" style="width:5em;">{{record.status}}</td>
      <td colspan="2">{{record.name}}</td>
      <td style="text-align:center;width:6em;">{{ record.meta_data.response.response_time_ms }} ms</td>
      <td class="detail">

        <a class="button" href="#popup_log_{{record_index}}">运行日志</a>
        <div id="popup_log_{{record_index}}" class="overlay">
          <div class="popup">
            <h2>请求和响应数据</h2>
            <a class="close" href="#record_{{record_index}}">&times;</a>

            <div class="content">
              <h3>请求信息:</h3>
              <div style="overflow: auto">
                <table>
                  {% for key, value in record.meta_data.request.items() %}
                      {% if key=="headers" %}
                        {% continue %}
                      {% endif %}
                    <tr>
                      <th>
                          {% if  key=='url'%}
                              接口请求地址
                          {% elif  key=='method'%}
                              请求方式
                          {% elif  key=='headers'%}
                             请求头信息
                          {% elif  key=='json'%}
                             请求json数据
                          {% elif  key=='body'%}
                             请求体
                          {% else %}
                              {{key}}
                          {% endif %}

                      </th>
                      <td>
{#                        {% if key == "headers" %}#}
{#                          {% for header_key, header_value in record.meta_data.request.headers.items() %}#}
{#                          <div>#}
{#                            <strong>{{ header_key }}</strong>: {{ header_value }}#}
{#                          </div>#}
{#                          {% endfor %}#}
{#                        {% elif key == "json" %}#}
{#                          {% for json_key, json_value in record.meta_data.request.json.items() %}#}
{#                          <div>#}
{#                            <strong>{{ json_key }}</strong>: {{ json_value }}#}
{#                          </div>#}
{#                          {% endfor %}#}
                        {% if key == "body" %}
                            <strong>{</strong>
                            {% for body_key, body_value in record.meta_data.request.body.items() %}
                          <div>
                            &nbsp;&nbsp;&nbsp;<strong>"{{ body_key }}"</strong>: "{{ body_value }}"
                            </div>
                          {% endfor %}
                            <strong>}</strong>
                        {% else %}
                          {{value}}
                        {% endif %}
                      </td>
                    </tr>
                  {% endfor %}
                </table>
              </div>

              <h3>接口响应:</h3>
              <div style="overflow: auto">
                <table>
                    {% for key, value in record.meta_data.response.items() %}
                      {% if key in ["text", "json", "elapsed_ms", "response_time_ms", "content_size", "content_type","headers"] %}
                        {% continue %}
                      {% endif %}
                      <tr>
                        <th>
                         {% if  key=='status_code'%}
                              状态码
{#                          {% elif  key=='headers'%}#}
{#                              头信息#}
{#                          {% elif  key=='encoding'%}#}
{#                             编码#}
                          {% elif  key=='content'%}
                             返回值
{#                          {% elif  key=='cookies'%}#}
{#                             cookies信息#}
                          {% else %}
                              {{key}}
                          {% endif %}

                        </th>
                        <td>
{#                          {% if key == "headers" %}#}
{#                            {% for header_key, header_value in record.meta_data.response.headers.items() %}#}
{#                            <div>#}
{#                              <strong>{{ header_key }}</strong>: {{ header_value }}#}
{#                            </div>#}
{#                            {% endfor %}#}
                          {% if key == "content" %}
                            {% if "image" in record.meta_data.response.content_type %}
                              <img src="{{ record.meta_data.response.content }}" />
                            {% else %}
{#                              <pre>{{ record.meta_data.response.text | e }}</pre>#}
                                <strong>{</strong>
                              {% for contentr_key,content_value in record.meta_data.response.content.items() %}
                              <div>
                                &nbsp;&nbsp;&nbsp;<strong>"{{ contentr_key }}"</strong>: "{{ content_value }}"
                              </div>
                              {% endfor %}
                                <strong>}</strong>

                            {% endif %}
                          {% else %}
                            {{value}}
                          {% endif %}
                        </td>
                      </tr>
                    {% endfor %}
                  </table>
              </div>

              <h3>验证:</h3>
              <div style="overflow: auto">
                  <table>
                    <tr>
                      <th>验证点</th>
                      <th>检测方式</th>
                      <th>期望值</th>
                      <th>实际值</th>
                    </tr>
                    {% for validator in record.meta_data.validators %}
                    <tr>
                      {% if validator.check_result == "pass" %}
                      <td class="passed">
                      {% elif validator.check_result == "fail" %}
                      <td class="failed">
                      {% elif validator.check_result == "unchecked" %}
                      <td class="unchecked">
                      {% endif %}
                        {{validator.check}}
                      </td>
                      <td>{{validator.comparator}}</td>
                      <td>{{validator.expect}}</td>
                      <td>{{validator.check_value}}</td>
                    </tr>
                    {% endfor %}
                  </table>
              </div>

              <h3>统计:</h3>
              <div style="overflow: auto">
                <table>
                  <tr>
                      <th>返回大小(字节)</th>
                      <td>{{ record.meta_data.response.content_size }}</td>
                    </tr>
                  <tr>
                    <th>响应时间(毫秒)</th>
                    <td>{{ record.meta_data.response.response_time_ms }}</td>
                  </tr>
{#                  <tr>#}
{#                    <th>elapsed(ms)</th>#}
{#                    <td>{{ record.meta_data.response.elapsed_ms }}</td>#}
{#                  </tr>#}
                </table>
              </div>

            </div>
          </div>
        </div>

        {% if record.attachment %}
          <a class="button" href="#popup_attachment_{{record_index}}">traceback</a>
          <div id="popup_attachment_{{record_index}}" class="overlay">
            <div class="popup">
              <h2>Traceback Message</h2>
              <a class="close" href="#record_{{record_index}}">&times;</a>
              <div class="content"><pre>{{ record.attachment }}</pre></div>
            </div>
          </div>
        {% endif %}

      </td>
      <td style="text-align:center;width:6em;">{{record.intf_type}}</td>
      {% for validator in record.meta_data.validators %}
          {% if validator.error_log %}
              <td style="text-align:center;width:9em; " >{{validator.error_log}}</td>
{#          {% else %}#}
{#              <td style="text-align:center;width:20%;">pass</td>#}
          {% endif %}

      {% endfor %}
    </tr>
  {% endfor %}
  </table>
  {% endfor %}
</body>